﻿using System.Globalization;
using SharedServiceLibrary;

namespace Central
{
    public partial class UcPump
    {
        public delegate void PumpEvent(int pumpIndex);

        public event PumpEvent StartPump;
        public event PumpEvent StopPump;

        private Pump _pump;
        private readonly int _index;

        public Pump Pump
        {
            get
            {
                return _pump;
            }
            set
            {
                _pump = value;
                ButtonStart.IsEnabled = !value.Running;
                ButtonStop.IsEnabled = value.Running;
            }
        }

        public UcPump(int index, Pump pump)
        {
            _index = index;

            InitializeComponent();

            TextBlockCapacity.Text = "Pumpekapacitet: " + pump.Capacity.ToString(CultureInfo.InvariantCulture) + " m3/t";
            Pump = pump;
        }

        private void ButtonStart_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            if (StartPump != null)
                StartPump(_index);
        }

        private void ButtonStop_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            if (StopPump != null)
                StopPump(_index);
        }
    }
}
